const BaseIpcHandler = require('../BaseIpcHandler');
const { LocalSystemInfo } = require('../../remote/systemInfo');
const { LocalSoftwareInfo } = require('../../remote/softwareInfo');

class LocalSystemInfoHandler extends BaseIpcHandler {
    async handle(event, params) {
        // 解析参数
        // console.log(`>> LocalSystemInfoHandler params = `, params);

        // 业务逻辑
        let result = null;
        try {
            // 获取本地系统的信息
            let system_query = new LocalSystemInfo();
            let system_info = system_query.getSystemInfo();
            // 获取关键软件的信息
            let software_query = new LocalSoftwareInfo();
            let software_info = software_query.getSoftwareInfo();
            system_info['software'] = software_info;
            result = { code: 0, msg: JSON.stringify(system_info) };
        } catch (err) {
            console.error(`Get local system info Failed!, Error = `, err);
            result = { code: -1, msg: err.msg };
        }

        // 返回结果
        // console.log(`LocalSystemInfoHandler result = `, result);
        if (event.from === 'localserver') {
            event.resp.send(result);
        } else {
            return result;
        }
    }
}

module.exports = LocalSystemInfoHandler;
